using Game.Main.Model;
using SimpleJSON;
using UnityEngine;

namespace Game.Component
{
	public class InfusionBagItem : BaseItem
	{
		public float fillAmount;

		protected SpriteRenderer waterSprite;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			waterSprite = model.Find("WaterFill").GetComponent<SpriteRenderer>();
			float num = waterSprite.sprite.texture.height;
			Rect textureRect = waterSprite.sprite.textureRect;
			float num2 = textureRect.yMin / num;
			float value = textureRect.yMax / num - num2;
			waterSprite.material.SetFloat("_StartY", num2);
			waterSprite.material.SetFloat("_TotalY", value);
			waterSprite.color = base.itemData.bodyColor;
			SetFillAmount(data.floatParam1 + 1f);
		}

		protected override void CheckColls()
		{
			for (int i = 0; i < itemCompColls.Count; i++)
			{
				ItemComponentTrigger.Type type = itemCompColls[i].trigger.type;
				if (type == ItemComponentTrigger.Type.InfusionBagBox)
				{
					BaseItem owner = itemCompColls[i].trigger.owner;
					if (owner.itemData.scriptType == 159 && ((InfusionSupportItem)owner).ChangeInfusionBag(this))
					{
						return;
					}
				}
			}
			base.CheckColls();
		}

		public void MinusFillAmount(float val)
		{
			if (fillAmount > 0f)
			{
				fillAmount -= val / 2f;
				if (fillAmount < 0f)
				{
					fillAmount = 0f;
				}
				SetFillAmount(fillAmount);
			}
		}

		protected void SetFillAmount(float val)
		{
			fillAmount = val;
			waterSprite.material.SetFloat("_Fill", fillAmount);
		}

		public override void PackData(JSONObject obj)
		{
			base.PackData(obj);
			obj["62"] = fillAmount - 1f;
		}
	}
}
